#pragma once

#include <windows.h>
#include <stdio.h>
#include <GL/glew.h>
#include <gl/freeglut.h>
#include <irrKlang.h>
#include <iostream>
#include <assert.h>
//#include <glm/glm.hpp>

#undef max
#undef min
#define sqr(x) x*x

using namespace std;
using namespace irrklang;

#define ErrorMsg(cond,msg) { if(cond) { cout << msg << endl; return; } }
#define ErrorMsgReturn(cond,msg,r) { if(cond) { cout << msg << endl; return r; } }

#define DELETE_PTR(p) { if(p!=NULL) { delete p; p = NULL; } }
#define DELETE_ARR(p) { if(p!=NULL) { delete [] p; p = NULL; } }

typedef unsigned __int8		uchar;
typedef unsigned __int16	ushort;
typedef unsigned __int32	uint;
typedef unsigned __int64	ulonglong;

float detectzero(float num);

/** PROPERTY_READONLY is used to declare a protected variable.
 We can use getter to read the variable.
 @param varType : the type of variable.
 @param varName : variable name.
 @param funName : "get + funName" is the name of the getter.
 @warning : The getter is a public virtual function, you should rewrite it first.
 The variables and methods declared after PROPERTY_READONLY are all public.
 If you need protected or private, please declare.
 */
#define PROPERTY_READONLY(varType, varName, funName)\
	protected: varType varName;\
	public: virtual varType get##funName(void);

#define PROPERTY_READONLY_PASS_BY_REF(varType, varName, funName)\
	protected: varType varName;\
	public: virtual const varType& get##funName(void);

/** PROPERTY is used to declare a protected variable.
 We can use getter to read the variable, and use the setter to change the variable.
 @param varType : the type of variable.
 @param varName : variable name.
 @param funName : "get + funName" is the name of the getter.
 "set + funName" is the name of the setter.
 @warning : The getter and setter are public virtual functions, you should rewrite them first.
 The variables and methods declared after PROPERTY are all public.
 If you need protected or private, please declare.
 */
#define PROPERTY(varType, varName, funName)\
	protected: varType varName;\
	public: virtual varType get##funName(void);\
	public: virtual void set##funName(varType var);

#define PROPERTY_PASS_BY_REF(varType, varName, funName)\
	protected: varType varName;\
	public: virtual const varType& get##funName(void);\
	public: virtual void set##funName(const varType& var);

/** SYNTHESIZE_READONLY is used to declare a protected variable.
 We can use getter to read the variable.
 @param varType : the type of variable.
 @param varName : variable name.
 @param funName : "get + funName" is the name of the getter.
 @warning : The getter is a public inline function.
 The variables and methods declared after SYNTHESIZE_READONLY are all public.
 If you need protected or private, please declare.
 */
#define SYNTHESIZE_READONLY(varType, varName, funName)\
	protected: varType varName;\
	public: virtual varType get##funName(void) const { return varName; }

#define SYNTHESIZE_READONLY_PASS_BY_REF(varType, varName, funName)\
	protected: varType varName;\
	public: virtual const varType& get##funName(void) const { return varName; }

/** SYNTHESIZE is used to declare a protected variable.
 We can use getter to read the variable, and use the setter to change the variable.
 @param varType : the type of variable.
 @param varName : variable name.
 @param funName : "get + funName" is the name of the getter.
 "set + funName" is the name of the setter.
 @warning : The getter and setter are public  inline functions.
 The variables and methods declared after SYNTHESIZE are all public.
 If you need protected or private, please declare.
 */
#define SYNTHESIZE(varType, varName, funName)\
	protected: varType varName;\
	public: virtual varType get##funName(void) const { return varName; }\
	public: virtual void set##funName(varType var){ varName = var; }

#define SYNTHESIZE_PASS_BY_REF(varType, varName, funName)\
	protected: varType varName;\
	public: virtual const varType& get##funName(void) const { return varName; }\
	public: virtual void set##funName(const varType& var){ varName = var; }

//	Use this define in mySingleton.h
//	---------------
//	class mySingleton {
//		SINGLETON_DECLARE(mySingleton);
//	};
//	---------------
#define SINGLETON_DECLARE(Singleton)\
	protected: static Singleton* Singleton##_Instance;\
	public: static Singleton* getInstance(void)

//	Use this define in mySingleton.cpp
//	---------------
//	#include "mySingleton.h"
//	SINGLETON_DEFINE(mySingleton);
//	---------------
//#define SINGLETON_DEFINE(Singleton)\ 
//	static Singleton* Singleton##_Instance = NULL;\
//	Singleton* Singleton::getInstance(void)\
//	{\ 
//		if(Singleton##_Instance == NULL)\ 
//			Singleton##_Instance = new Singleton();\
//		return Singleton##_Instance;\ 
//	}

#define SINGLETON_DEFINE(Singleton)\
	Singleton* Singleton::Singleton##_Instance = NULL;\
	Singleton* Singleton::getInstance(void)\
	{\
		if(Singleton##_Instance == NULL)\
			Singleton##_Instance = new Singleton();\
		return Singleton##_Instance;\
	}